package fons.navigator.ui.configurations;

import java.awt.Component;

import javax.swing.JDialog;

import fons.navigator.util.SwingUtils;
import fons.navigator.util.settings.Configurable;
import fons.navigator.util.settings.Configuration;

public class ConfigurationDialog extends JDialog {
	private static final long serialVersionUID = 1L;
	
	private final Configuration configuration;
	private final Configurable configurable;
	
	@SuppressWarnings("unused")
	private final ConfigurationDialogLayoutBuilder builder; 
	private boolean ok = false;
	
	public ConfigurationDialog (Configurable configurable, String title, Component parent, String message) {
		super(SwingUtils.getWindowFor(parent), title, ModalityType.DOCUMENT_MODAL);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.configurable = configurable;
		this.configuration = configurable.getConfiguration();
		this.configuration.push();
	
		builder = new ConfigurationDialogLayoutBuilder(this, message);
	}
		
	public ConfigurationDialog(Configuration configuration, String title,
			Component parent, String message) {
		super(SwingUtils.getWindowFor(parent), title, ModalityType.DOCUMENT_MODAL);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.configurable = null;
		this.configuration = configuration;
		this.configuration.push();		
		
		builder = new ConfigurationDialogLayoutBuilder(this,  message);
	}

	public final Configuration getConfiguration() {
		return configuration;
	}
	
	public final Configurable getConfigurable() {
		return configurable;
	}

	public void revert() {
		configuration.pop();
	}
	
	public boolean isOK () {
		return ok;
	}
	
	protected void setOK (boolean ok) {
		this.ok = ok;
	}
}
